// pages/recruit/deliveryList/deliveryList.js
const app = getApp();
const time = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 基本参数
    select_text: "全部",
    status: '',

    //招聘信息
    recruit_info: [],
    callList: [],
    stayList: [],
    CollectList: [],
    qiangList: [],

    page_host: 1,

    //submit 封装 Start
    area_name: '',
    plat_id: '',
    anchor_type: '',
    pay_low: '',
    pay_high: '',
    salary_type: '',
    keep_pay: '',
    page: 1,
    role: app.register_info.register_role,
    //submit 封装 End

    // modalShow
    select_flag: true,

    //切换
    currentData: 0,

  },
  //去独立 简历页
  go_singleRecruit(e) {
    console.log(e)
    let resume_id = e.currentTarget.dataset.resume_id;
    wx.navigateTo({
      url: '../singleRecruit/singleRecruit?resume_id=' + resume_id + '&stay=true',
    })
  },

  //切换 Start
  //获取当前滑块的index
  bindchange: function(e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function(e) {
    const that = this;

    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {

      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  //切换 End





  //小播推荐加载
  LoadHost: function(e) {
    let that = this;
    let page_host = this.data.page_host;
    page_host = page_host + 1;
    that.setData({
      page_host: page_host
    })
    this.List_Host();
  },
  //小播推荐
  HostList(_page) {
    let that = this;
    wx.request({
      method: 'POST',
      url: app.globalData.url + 'api/recommend/resume/list',
      data: {
        token: app.globalData.token,
        page: _page
      },
      success: function(e) {
        console.log(e)
        if (e.data.data.current_page > e.data.data.total_page) {
          console.log("到底了");
          wx.showToast({
            title: '到底啦~',
            icon: 'none',
          })
        } else {
          if (that.data.page_host == 1) {
            let CollectList_old = e.data.data.resumes;
            CollectList_old.forEach(function (value, index) {
              value.create_time = time.formatTimeTwo(value.create_time, 'M月D日');
            })
            that.setData({
              CollectList: CollectList_old,
            })
          } else {
            // console.log("不不不不不");
            let CollectList = that.data.CollectList;
            let _CollectList = e.data.data.resumes;
            _CollectList.forEach(function (value, index) {
              value.create_time = time.formatTimeTwo(value.create_time, 'M月D日');
            })
            CollectList.push(..._CollectList);
            console.log(CollectList);
            that.setData({
              CollectList: CollectList,
            })
          }
        }
        wx.hideLoading();
      }
    })
  },
  // 小播推荐
  List_Host: function(e) {
    let that = this;
    let page_host = this.data.page_host
    that.HostList(page_host);
  },
  //加载 会长拨打电话
  get_call() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/welfare/guild/list',
      data: {
        token: app.globalData.token,
        type: 1,
      },
      method: 'POST',
      success: function(e) {
        // console.log(e.data.data.resume)     time.formatTimeTwo(app.globalData.start_date, 'Y年M月D日')
        let callList_old = e.data.data.resume;
        callList_old.forEach(function(value, index) {
          value.create_time = time.formatTimeTwo(value.create_time, 'M月D日');
        })
        console.log(callList_old)
        that.setData({
          callList: callList_old,
        })
      },
    })
  },
  //加载 留电话列表
  get_stay() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/welfare/guild/list',
      data: {
        token: app.globalData.token,
        type: 2,
      },
      method: 'POST',
      success: function(e) {
        // console.log(e.data.data.resume)
        let stayList_old = e.data.data.resume;
        stayList_old.forEach(function(value, index) {
          value.create_time = time.formatTimeTwo(value.create_time, 'M月D日');
        })
        that.setData({
          stayList: stayList_old,
        })

      },
    })
  },
  //加载 留电话列表
  get_qiang() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/welfare/grade/list',
      data: {
        token: app.globalData.token
      },
      method: 'POST',
      success: function (e) {
        // console.log(e.data.data.resume)
        let qiangList_old = e.data.data.resume;
        qiangList_old.forEach(function (value, index) {
          value.create_time = time.formatTimeTwo(value.create_time, 'M月D日');
        })
        that.setData({
          qiangList: qiangList_old,
        })

      },
    })
  },
  //去详情
  go_detail(e) {
    console.log(e)
    let recruit_id = e.currentTarget.dataset.deatil_id
    wx.navigateTo({
      url: '../deliveryDetail/deliveryDetail?recruit_id=' + recruit_id,
    })
  },

  //获取列表
  get_deliveryList: function() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/anchor/send/resume',
      data: {
        token: app.globalData.token,
      },
      method: 'POST',
      success: function(e) {
        // console.log(e)
        // 普通情况
        that.setData({
          recruit_info: e.data.data.resume,
        });
      },
    })
  },

  // 点击选择时间
  click_select() {
    let that = this;
    that.setData({
      select_flag: false,
    })
  },

  // 关闭蒙版
  modal_hide() {
    this.setData({
      select_flag: true,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    // this.get_deliveryList();
    // this.get_call();
    // this.get_stay();
    if (options.currentData){
      this.setData({
        currentData: options.currentData
      })
    }
    let that = this;
    let page_host = this.data.page_host
    that.HostList(page_host);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.get_deliveryList();
    this.get_call();
    this.get_stay();
    this.get_qiang();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})